'use strict';

define(function(require,exports,module){
	var React = require('react');
	var $ = require('jquery');
	var Highcharts = require('highcharts');
	var numberFormat = require('numberFormat');
		
	module.exports = React.createClass({
		getInitialState:function(){
            return {
				data:[]
			};
		},
		componentDidMount:function(){


			if(this.props.data){
				var data_array = [];
				var all_count = 0;
				for(var i=0;i<this.props.data.length;i++){
					all_count += parseInt(this.props.data[i].v);
					data_array.push([this.props.data[i].name,this.props.data[i].v]);
				}
				all_count = numberFormat('#,###.',all_count);

				new Highcharts.Chart({
					colors: [
						'#058DC7',
						'#50B432',
						'#ED561B',
						'#DDDF00',
						'#24CBE5',
						'#64E572',
						'#FF9655',
						'#FFF263', 
						'#6AF9C4'
					], 
					chart: {
			            renderTo: this.props.id,
			            polar: true
			        },
					title: {
	                	text: this.props.title + ':' + all_count
		            },
		            tooltip: {
						formatter:function(){
							return this.key+'开机量: '+Highcharts.numberFormat(this.y,0,'.',',')+',占总量<b>'+Highcharts.numberFormat(this.percentage, 2) +'%</b>'
						}
						
		            },
		            plotOptions: {
		                pie: {
		                    allowPointSelect: true,
		                    cursor: 'pointer',
		                    dataLabels: {
		                        enabled: false
		                    },
		                    showInLegend: true
		                }
		            },
		            series: [{
		                type: 'pie',
		                name: this.props.title,
		                data: data_array
		            }]
				});
			}
			
		},
		render:function(){
			return (
				<div className={this.props.className} id={this.props.id}></div>
				);
		}
	});
});